<?php

/**
 * Vote form.
 *
 * @package    lomejorde
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class VoteForm extends BaseVoteForm
{
    public function configure()
    {
        unset($this['created_at'],$this['updated_at']);

        $this->widgetSchema['user_id'] = new sfWidgetFormInputHidden();
        $this->widgetSchema['category_id'] = new sfWidgetFormInputHidden();

        $this->widgetSchema['candidate_id'] = new sfWidgetFormDoctrineChoice(array(
                'model' => $this->getRelatedModelName('Candidate'),
                'add_empty' => false,
                'multiple' => false,
                'expanded'=> true,
                'query' => Doctrine::getTable('Nominee')->getQueryRetrieveNomineesByCategoryId($this->getObject()->getCategoryId()),
                'renderer_class' => 'myWidgetFormSelectRadio'
            ), array(
                'class' => 'voting-option'
            )
        );
        
        $this->widgetSchema['candidate_id']->setLabel(
            '<img class="voting-form-category-image" src="/uploads/'.$this->getObject()->getCategory()->getThumb2().'" atl="'.$this->getObject()->getCategory().'" />'
        );
        
        $this->validatorSchema['candidate_id']->setOption('required',false);
        
        $this->widgetSchema->setFormFormatterName('voting');
    }
    
    public static function formValuesAreBlank(array $values)
    {
        $fieldNames = array_diff(Doctrine::getTable('Vote')->getFieldNames(), array(
            'id',
            'user_id',
            'category_id',
        ));

        return parent::_formValuesAreBlank($fieldNames, $values);
    }
}
